package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.common.result.PageResult;
import com.itheima.common.result.Result;
import com.itheima.dto.YddCatePageQueryDTO;
import com.itheima.mapper.YddCateMapper;
import com.itheima.pojo.YddCate;
import com.itheima.service.YddCateService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

@Service
public class YddCateServiceImpl extends ServiceImpl<YddCateMapper, YddCate> implements YddCateService {


    /**
     * 分类管理-分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResult pageQuery(YddCatePageQueryDTO dto) {
        IPage<YddCate> page = new Page<>(dto.getPage(),dto.getLimit());
        LambdaQueryWrapper<YddCate> lqw = new LambdaQueryWrapper<>();
        lqw.like(YddCate::getCatename,dto.getCatename());
        page(page,lqw);
        List<YddCate> records = page.getRecords();
        return new PageResult(page.getTotal(),page.getCurrent(),records,page.getSize(),page.getPages());
    }

    /**
     * 分类详情
     *
     * @param id
     * @return
     */
    @Override
    public YddCate rowInfoCate(Integer id) {
        YddCate byId = getById(id);
        return byId;
    }

    /**
     * 分类列表-全部
     *
     * @return
     */
    @Override
    public Result allCate() {
        List<YddCate> cateList = list();
        return Result.success(cateList);
    }


}
